package cn.iocoder.yudao.module.erp.controller.admin.dpitem.dpeastlistyw;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.erp.controller.admin.dpitem.dpeastlistyw.vo.DpEastListYwPageReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.dpitem.dpeastlistyw.vo.DpEastListYwRespVO;
import cn.iocoder.yudao.module.erp.controller.admin.dpitem.dpeastlistyw.vo.DpEastListYwSaveReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.dplist.DpEastListYwDO;
import cn.iocoder.yudao.module.erp.service.dpeast.DpEastListYwService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;
import javax.servlet.http.*;
import java.io.IOException;
import java.util.List;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 义乌东线清单")
@RestController
@RequestMapping("/erp/dp-east-list-yw")
@Validated
public class DpEastListYwController {

    @Resource
    private DpEastListYwService dpEastListYwService;

    @PostMapping("/create")
    @Operation(summary = "创建义乌东线清单")
    // @PreAuthorize("@ss.hasPermission('erp:dp-east-list-yw:create')")
    public CommonResult<Long> createDpEastListYw(@Valid @RequestBody DpEastListYwSaveReqVO createReqVO) {
        return success(dpEastListYwService.createDpEastListYw(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新义乌东线清单")
    // @PreAuthorize("@ss.hasPermission('erp:dp-east-list-yw:update')")
    public CommonResult<Boolean> updateDpEastListYw(@Valid @RequestBody DpEastListYwSaveReqVO updateReqVO) {
        dpEastListYwService.updateDpEastListYw(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除义乌东线清单")
    @Parameter(name = "id", description = "编号", required = true)
    // @PreAuthorize("@ss.hasPermission('erp:dp-east-list-yw:delete')")
    public CommonResult<Boolean> deleteDpEastListYw(@RequestParam("id") Long id) {
        dpEastListYwService.deleteDpEastListYw(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得义乌东线清单")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    // @PreAuthorize("@ss.hasPermission('erp:dp-east-list-yw:query')")
    public CommonResult<DpEastListYwRespVO> getDpEastListYw(@RequestParam("id") Long id) {
        DpEastListYwDO dpEastListYw = dpEastListYwService.getDpEastListYw(id);
        return success(BeanUtils.toBean(dpEastListYw, DpEastListYwRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得义乌东线清单分页")
    // @PreAuthorize("@ss.hasPermission('erp:dp-east-list-yw:query')")
    public CommonResult<PageResult<DpEastListYwRespVO>> getDpEastListYwPage(@Valid DpEastListYwPageReqVO pageReqVO) {
        PageResult<DpEastListYwDO> pageResult = dpEastListYwService.getDpEastListYwPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, DpEastListYwRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出义乌东线清单 Excel")
    // @PreAuthorize("@ss.hasPermission('erp:dp-east-list-yw:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportDpEastListYwExcel(@Valid DpEastListYwPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<DpEastListYwDO> list = dpEastListYwService.getDpEastListYwPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "义乌东线清单.xls", "数据", DpEastListYwRespVO.class,
                        BeanUtils.toBean(list, DpEastListYwRespVO.class));
    }

}